package com.gk.javaservice.util.file;

import com.sun.jna.platform.win32.WinDef.DWORD;
import com.sun.jna.ptr.IntByReference;

public class VolumeInformation {
    public static String getFileSystemName(String lpRootPathName) {
        String msg = "";
        char[] lpVolumeNameBuffer = new char[256];
        DWORD nVolumeNameSize = new DWORD(256);
        IntByReference lpVolumeSerialNumber = new IntByReference();
        IntByReference lpMaximumComponentLength = new IntByReference();
        IntByReference lpFileSystemFlags = new IntByReference();
        char[] lpFileSystemNameBuffer = new char[256];
        DWORD nFileSystemNameSize = new DWORD(256);
        lpVolumeSerialNumber.setValue(0);
        lpMaximumComponentLength.setValue(256);
        lpFileSystemFlags.setValue(0);

////        System.out.println(""+);
//        System.out.println("lpVolumeNameBuffer:"+lpVolumeNameBuffer);
//        System.out.println("nVolumeNameSize:"+nVolumeNameSize);
//        System.out.println("lpVolumeSerialNumber:"+lpVolumeSerialNumber);
//        System.out.println("lpMaximumComponentLength:"+lpMaximumComponentLength);
//        System.out.println("lpFileSystemFlags:"+lpFileSystemFlags);
//        System.out.println("lpFileSystemNameBuffer:"+lpFileSystemNameBuffer);
//        System.out.println("nFileSystemNameSize:"+nFileSystemNameSize);

        Kernel32.INSTANCE.GetVolumeInformation(
                lpRootPathName,
                lpVolumeNameBuffer,
                nVolumeNameSize,
                lpVolumeSerialNumber,
                lpMaximumComponentLength,
                lpFileSystemFlags,
                lpFileSystemNameBuffer,
                nFileSystemNameSize);
//        System.out.println("Last error: "+Kernel32.INSTANCE.GetLastError()+"\n\n");
//        System.out.println(lpFileSystemNameBuffer);
        String fs = new String(lpFileSystemNameBuffer);
        msg = fs.trim();
        return msg;
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(getFileSystemName("E:\\"));
    }
}
